package com.wlts.wzy.sys_shiro.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wlts.wzy.configBean.shiro.SysAuthorizationInfo;
import com.wlts.wzy.expand.MyLambdaQueryWrapper;
import com.wlts.wzy.sys_shiro.entity.SysRole;
import com.wlts.wzy.sys_shiro.entity.SysUser;
import com.wlts.wzy.sys_shiro.mapper.SysUserMapper;
import com.wlts.wzy.sys_shiro.service.ISysRoleService;
import com.wlts.wzy.sys_shiro.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 * 宅配商品类型表 服务实现类
 * </p>
 *
 * @author wuzhiyong
 * @since 2019-03-27
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {

    @Autowired
    private ISysRoleService roleService;


    @Override
    public SysAuthorizationInfo getAuthor(String name) {

        SysAuthorizationInfo authorizationInfo = new SysAuthorizationInfo();

        if(name.equals("admin")){

            List<SysRole> sysRoleList = roleService.list(new MyLambdaQueryWrapper<SysRole>().eq(SysRole::getDelFlag, "0"));

            Set<String> stringSet = sysRoleList.stream().map(SysRole::getRolename).collect(Collectors.toSet());

            authorizationInfo.setRoles(stringSet);
        }else {
            authorizationInfo.setRoles(new HashSet<>());
        }

        authorizationInfo.setPermissions(new HashSet<>());

        return authorizationInfo;
    }
}
